package com.alibaba.citrus.cr.mn.order.center.forecastorder.convert;

import com.epoch.app.crforecastsales.bo.ForecastOrderBO;
import com.epoch.app.crforecastsales.bo.ForecastOrderLineBO;
import com.epoch.app.mnordercenter.model.dto.CreateForecastDetailResponseDTO;
import com.epoch.app.mnordercenter.model.dto.CreateForecastResponseDTO;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;

/**
 * @description TODO
 * @date 2023/04/27 13:28
 * @version 1.0
 */
public class ForecastOrderBOToResponseDTOConvertor {

    public static CreateForecastResponseDTO convert(ForecastOrderBO forecastOrderBO) {
        CreateForecastResponseDTO createForecastResponseDTO = new CreateForecastResponseDTO();
        createForecastResponseDTO.setSalesOrderNo(forecastOrderBO.getOrderBizId());
        createForecastResponseDTO.setSourceOrderNo(forecastOrderBO.getSourceOrderNo());
        createForecastResponseDTO.setReqNo(forecastOrderBO.getReqNo());
        createForecastResponseDTO.setForecastDetailResponseDTOS(convertOrderLine(forecastOrderBO.getForecastOrderLineBOList()));
        return createForecastResponseDTO;
    }

    private static List<CreateForecastDetailResponseDTO> convertOrderLine(List<ForecastOrderLineBO> orderLines) {
        if (CollectionUtils.isEmpty(orderLines)) {
            return Lists.newArrayList();
        }
        List<CreateForecastDetailResponseDTO> responses = Lists.newArrayList();
        for (ForecastOrderLineBO orderLine : orderLines) {
            CreateForecastDetailResponseDTO response = lineBOToDTO(orderLine);
            responses.add(response);
        }
        return responses;
    }

    public static CreateForecastDetailResponseDTO lineBOToDTO(ForecastOrderLineBO orderLine) {
        return CreateForecastDetailResponseDTO.builder()
                .sourceLineNum(orderLine.getSourceLineNum())
                .lineNum(orderLine.getLineNum())
                .build();
    }

}
